﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DBSourceToolsLib.CodeParser
{
    public class ParseObject
    {
        public const int VERB = 1000;
        public const int VARIABLE = 1010;
        public const int BRACE = 1020;
        public const int SPACE = 1030;
        public const int TOKEN = 1040;
        public const int NEWLINE = 1050;
        public const int LIST = 1060;
        public const int LITERAL = 1070;
        public const int TABLE = 1080;
        public const int UNKNOWN = -1;
        private int m_LineIdx = -1;

        public int LineIdx
        {
            get { return m_LineIdx; }
            set { m_LineIdx = value; }
        }
        private int m_WordIdx = -1;

        public int WordIdx
        {
            get { return m_WordIdx; }
            set { m_WordIdx = value; }
        }

        protected int m_Value, m_Type;
        protected string m_Data = "";
        private bool m_IsResolved = false;

        public bool IsResolved
        {
            get { return m_IsResolved; }
            set { m_IsResolved = value; }
        }

        public string Data
        {
            get { return m_Data; }
            set { m_Data = value; }
        }

        public ParseObject(int val, int type, bool bIsResolved, int iLineIdx, int iWordIdx)
        {
            m_Value = val;
            m_Type = type;
            m_IsResolved = bIsResolved;
            m_LineIdx = iLineIdx;
            m_WordIdx = iWordIdx;
        }

        public int Value
        {
            get { return m_Value; }
        }
        public int ParseType
        {
            get { return m_Type; }
        }

        public virtual string DumpToString()
        { 
            return String.Format("{0} |{1}| {2} [{3},{4}]", GetTypeString(), m_Data, (m_IsResolved ? "1" : "0")
                , m_LineIdx, m_WordIdx);
        }
        protected string GetTypeString()
        {
            switch (m_Type)
            {
                case VERB:
                    return "VERB";
                case VARIABLE:
                    return "VARIABLE";
                case BRACE:
                    return "BRACE";
                case SPACE:
                    return "SPACE";
                case TOKEN:
                    return "TOKEN";
                case NEWLINE:
                     return "NEWLINE crlf";
                case LITERAL:
                    return "LITERAL";
                case TABLE:
                    return "TABLE";
                default:
                    return "UNKNOWN";
            }

        }
    }
}
